﻿@{
    Layout = "_Layout.cshtml";
}
<style>
    .error {
        color: #ff0000
    }
</style>
<div class="huanjing-box">
    <div class="pr-title"><h3>系统环境检测</h3></div>
    <table border="0" cellspacing="0" cellpadding="0" class="tb">
        <thead>
            <tr>
                <th width="50%">参数</th>
                <th>值</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>服务器IP</td>
                <td>@Request.ServerVariables["LOCAL_ADDR"]</td>
            </tr>

            <tr>
                <td>服务器域名</td>
                <td>@Request.Url.Host</td>
            </tr>
            <tr>
                <td>端口</td>
                <td>@Request.Url.Port</td>
            </tr>
            <tr>
                <td>服务器操作系统</td>
                <td>@Environment.OSVersion.ToString()</td>
            </tr>
            <tr>
                <td>IIS版本</td>
                <td>@Request.ServerVariables["SERVER_SOFTWARE"]</td>
            </tr>
            <tr>
                <td>.NET引擎版本</td>
                <td>@(Environment.Version.Major).@Environment.Version.Minor.@Environment.Version.Build.@Environment.Version.Revision</td>
            </tr>
            <tr>
                <td>系统安装目录</td>
                <td>@Request.PhysicalApplicationPath</td>
            </tr>
        </tbody>
    </table>
</div>


<div class="huanjing-box">
    <div class="pr-title"><h3>目录权限检测</h3></div>
    <table border="0" cellspacing="0" cellpadding="0" class="tb">
        <thead>
            <tr>
                <th>目录/文件</th>
                <th>写入权限（必须）</th>
                <th>删除权限（必须）</th>
                <th>解压权限</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>/Web.Config</td>
                <td><span class="permssion basic-permssion" data-path="Config" data-permission="write"></span></td>
                <td>-</td>
                <td>-</td>
            </tr>
            <tr>
                <td>/Config</td>
                <td><span class="permssion basic-permssion" data-path="Config" data-permission="write"></span></td>
                <td>-</td>
                <td>-</td>
            </tr>
            <tr>
                <td>/Entities</td>
                <td><span class="permssion basic-permssion" data-path="Entities" data-permission="write"></span></td>
                <td>-</td>
                <td>-</td>
            </tr>
            <tr>
                <td>/AppData</td>
                <td><span class="permssion basic-permssion" data-path="AppData" data-permission="write"></span></td>
                <td><span class="permssion basic-permssion" data-path="AppData" data-permission="delete"></span></td>
                <td><span class="permssion decompress-permssion" data-path="AppData" data-permission="decompress"></span></td>
            </tr>
            <tr>
                <td>/AppPlugins</td>
                <td><span class="permssion basic-permssion" data-path="AppPlugins" data-permission="write"></span></td>
                <td><span class="permssion basic-permssion" data-path="AppPlugins" data-permission="write"></span></td>
                <td><span class="permssion decompress-permssion" data-path="AppData" data-permission="decompress"></span></td>
            </tr>
            <tr>
                <td>/Upload</td>
                <td><span class="permssion basic-permssion" data-path="Upload" data-permission="write"></span></td>
                <td><span class="permssion basic-permssion" data-path="Upload" data-permission="delete"></span></td>
                <td><span class="permssion decompress-permssion" data-path="AppData" data-permission="decompress"></span></td>
            </tr>
        </tbody>
    </table>
</div>
<div class="btn-box">
    <input name="上一步" type="submit" id="bt_next" class="btn btn-back" value="上一步" onclick="location.href='@Url.ActionUrl("Index")'" />
    <input name="下一步" type="submit" id="bt_next" class="btn btn-next" value="下一步" onclick="Next()" />
    <div class="right"><input type="checkbox" id="uncheckDecompress" />跳过解压权限检测(后续的在线升级，插件安装将受限)</div>
</div>
<script type="text/javascript">

    $(".setpbox").css("width", "400px");
    var $permssion = $(".permssion");
    var $basicPermssion = $(".basic-permssion");
    var $decompressPermssion = $(".decompress-permssion");
    $permssion.each(function () {
        var $this = $(this);
        var path = $this.attr("data-path");
        var type = $this.attr("data-permission");
        var options = { url: "@Url.ActionUrl("GetPermission")", async: false, dataType: "text", data: { path: path, type: type } };
        Ajax(options, function (data) {
            $this.text(data);
            if (data == "×")
            {
                $this.addClass("error");
            }
            else
            {
                $this.removeClass("error");
            }
        });
    });

    function Next()
    {
        //检查基本权限
        var basicPermssion= true, decompressPermssion=true;
        $basicPermssion.each(function () {
            var $this = $(this);
            if ($this.hasClass("error"))
            {
                basicPermssion = false;
                return true;
            }
        });
        if (!$("#uncheckDecompress").prop("checked"))
        {
            $decompressPermssion.each(function ()
            {
                var $this = $(this);
                if ($this.hasClass("error")) {
                    decompressPermssion = false;
                    return true;
                }
            });
        }

        if (!basicPermssion)
        {
           Alert("目录基本权限未通过检测，请先设置好目录权限！");
           return false;
       }
       if (!decompressPermssion) {
           Alert("目录解压权限未通过检测，您可以勾选右下角的跳过解压权限检测忽略检测！");
           return false;
       }

       location.href = "@Url.ActionUrl("Step3")";

    }
</script>
